package main

import (
	"context"
	"fmt"
	"go.etcd.io/etcd/clientv3"
	"time"
)

func main() {
	cli, err := clientv3.New(clientv3.Config{
		Endpoints:   []string{"10.10.10.101:12379"},
		DialTimeout: 5 * time.Second,
	})
	if err != nil {
		// handle error!
		fmt.Printf("connect to etcd failed, err:%v\n", err)
		return
	}
	fmt.Println("connect to etcd success")
	defer cli.Close()

	// put
	ctx, cancel := context.WithTimeout(context.Background(), time.Second)
	value := `[{"path":"F:/go/src/go-the-way-of-learning/day10/3log_agent_project/etcd_put/nginx.log", "topic":"web_log"},{"path":"F:/go/src/go-the-way-of-learning/day10/3log_agent_project/etcd_put/redis.log", "topic":"redis_log"}]`
	_, err = cli.Put(ctx, "/logagent/192.168.5.24/collect_config", value)
	cancel()
	if err != nil {
		fmt.Printf("put to etcd failed, err:%v\n", err)
		return
	}

}
